package com.qc.wintrax.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.qc.wintrax.R;
import com.qc.wintrax.WTApplication;
import com.qc.wintrax.adapter.LineListAdapter;
import com.qc.wintrax.utils.LogUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import greendao.LineName;

/**
 * @author xiaobaodou
 * @Description:() create at  2016/7/14 17:00
 **/
public class HistoryFragment extends BaseFragment {

    @Bind(R.id.history_txt)
    TextView historyTxt;
    @Bind(R.id.line_listview)
    ListView lineListview;

    private List<LineName> lineNameList;
    private LineListAdapter lineListAdapter;
    private boolean isPrepared;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_history, container, false);
        ButterKnife.bind(this, view);
        isPrepared = true;
        getValues();
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void getValues() {
        lineNameList = WTApplication.getGSDaoSession().getLineNameDao().loadAll();
//        for (int j = 0 ; j<lineNameList.size();j++){
//            String name = lineNameList.get(j).getMap_title();
//            long id = lineNameList.get(j).getId();
//            LogUtil.e("获取的主键是---"+id);
//            LogUtil.e("获取的名字是---"+name);
//        }
        if (lineNameList != null && lineNameList.size() > 0) {
            lineListview.setVisibility(View.VISIBLE);
        }
        lineListAdapter = new LineListAdapter(getActivity(), lineNameList, R.layout.line_item);
        lineListview.setAdapter(lineListAdapter);
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtil.e("History+111111111");
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (isVisible() && isResumed()) {
            getValues();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        LogUtil.e("History+222222222");
    }

    @Override
    public void onStart() {
        super.onStart();
        LogUtil.e("History+0000000000");
    }

    @Override
    public void onStop() {
        super.onStop();
        LogUtil.e("History+77777777");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        LogUtil.e("History+33333333");
        ButterKnife.unbind(this);
    }
}
